// V-admin/src/api/admin.ts
import request from './request'

export const adminAPI = {
  // 获取仪表板数据
  getDashboardStats: () => {
    return request.get('/admin/dashboard')
  },
  
  // 活动管理
  getActivities: (params?: any) => {
    return request.get('/admin/activities', { params })
  },
  
  getActivityById: (id: number) => {
    return request.get(`/admin/activities/${id}`)
  },
  
  createActivity: (data: any) => {
    return request.post('/admin/activities', data)
  },
  
  updateActivity: (id: number, data: any) => {
    return request.put(`/admin/activities/${id}`, data)
  },
  
  deleteActivity: (id: number) => {
    return request.delete(`/admin/activities/${id}`)
  },
  
  updateActivityStatus: (id: number, status: string) => {
    return request.put(`/admin/activities/${id}/status`, { status })
  },
  
  // 商品管理
  getProducts: (params?: any) => {
    return request.get('/admin/products', { params })
  },
  
  getProductById: (id: number) => {
    return request.get(`/admin/products/${id}`)
  },
  
  createProduct: (data: any) => {
    return request.post('/admin/products', data)
  },
  
  updateProduct: (id: number, data: any) => {
    return request.put(`/admin/products/${id}`, data)
  },
  
  deleteProduct: (id: number) => {
    return request.delete(`/admin/products/${id}`)
  },
  
  updateProductStatus: (id: number, status: string) => {
    return request.put(`/admin/products/${id}/status`, { status })
  },
  
  // 商品图片管理 - 新增API
  uploadProductImages: (productId: number, formData: FormData) => {
    return request.post(`/admin/products/${productId}/images`, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  deleteProductImage: (imageId: number) => {
    return request.delete(`/admin/products/images/${imageId}`)
  },
  
  sortProductImages: (productId: number, imageIds: number[]) => {
    return request.put(`/admin/products/${productId}/images/sort`, { imageIds })
  },
  
  setProductCover: (imageId: number) => {
    return request.put(`/admin/products/images/${imageId}/cover`)
  },
  
  // 订单管理
  getOrders: (params?: any) => {
    return request.get('/admin/orders', { params })
  },
  
  updateOrderStatus: (id: number, status: string) => {
    return request.put(`/admin/orders/${id}/status`, { status })
  },
  
  // 订单详情
  getOrderById: (id: number) => {
    return request.get(`/admin/orders/${id}`)
  },

  // 订单统计 - 修改路径避免路由冲突
  getOrderStats: () => {
    return request.get('/admin/orders-stats')  // 这里修改了路径
  },

  // 批量更新订单状态
  bulkUpdateOrderStatus: (data: { orderIds: number[], status: string }) => {
    return request.put('/admin/orders/bulk-status', data)
  },
  
  // 用户管理
  getUsers: (params?: any) => {
    return request.get('/admin/users', { params })
  },
  
  getAnchors: (params?: any) => {
    return request.get('/admin/anchors', { params })
  },
  
  // 用户信息
  getAdminProfile: () => {
    return request.get('/admin/profile')
  },
// 数据分析API
getSalesAnalytics: (params?: any) => {
  return request.get('/admin/analytics/sales', { params })
},

getUserAnalytics: (params?: any) => {
  return request.get('/admin/analytics/users', { params })
},

getActivityAnalytics: (params?: any) => {
  return request.get('/admin/analytics/activities', { params })
},

getOverviewAnalytics: () => {
  return request.get('/admin/analytics/overview')
},

// 粉丝管理API
getFansList: (params?: any) => {
  return request.get('/admin/fans/list', { params })
},

getFanDetail: (id: number) => {
  return request.get(`/admin/fans/${id}`)
},

getFansStats: () => {
  return request.get('/admin/fans/stats')  // 确保这里是 /admin/fans/stats
},

exportFansData: () => {
  return request.get('/admin/fans/export')
},
// 视频管理API
getVideos: (params?: any) => {
  return request.get('/admin/videos', { params })
},

getVideoById: (id: number) => {
  return request.get(`/admin/videos/${id}`)
},

createVideo: (data: any) => {
  return request.post('/admin/videos', data)
},

updateVideo: (id: number, data: any) => {
  return request.put(`/admin/videos/${id}`, data)
},

deleteVideo: (id: number) => {
  return request.delete(`/admin/videos/${id}`)
},

updateVideoStatus: (id: number, status: number) => {
  return request.put(`/admin/videos/${id}/status`, { status })
},

uploadVideoFile: (videoId: number, formData: FormData) => {
  return request.post(`/admin/videos/${videoId}/upload`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
},

uploadVideoCover: (videoId: number, formData: FormData) => {
  return request.post(`/admin/videos/${videoId}/cover`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
},

getVideoStats: () => {
  return request.get('/admin/videos-stats')
}
}